package fr.idak.spring.tiles.service;

import java.util.List;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import fr.idak.spring.tiles.dao.LanguageDao;
import fr.idak.spring.tiles.hibernate.entity.Language;
import fr.idak.spring.tiles.util.Loggable;

@Service("languageService")
public class LanguageServiceImpl implements LanguageService {

	@Loggable
	private Logger LOGGER;
	
	@Autowired
	private LanguageDao languageDao;
	
	public Language createLanguage(Language language) {
		return languageDao.create(language);
	}

	public Language saveLanguage(Language language) {
		
		if(language !=null && language.getLanguageId() != 0){
			return languageDao.update(language);
		}else{
			return languageDao.create(language);
		}

	}

	public Language findLanguageById(Integer languageId) {
		return languageDao.read(languageId);
	}

	public void deleteLanguage(Language language) {
		languageDao.delete(language);
	}

	public List<Language> getLanguageByReleaseDate(String releaseDate) {
		return languageDao.getLanguageByReleaseDate(releaseDate);
	}

	public List<Language> getAllLanguages() {
		return languageDao.getAll();
	}

	public List<Language> getLanguagesByIndex(int begin, int end) {
		return languageDao.getLanguagesByIndex(begin, end);
	}

	public int countRecords() {
		return languageDao.count();
	}
}
